{include file="public/header"/}
</head>
<body>
<style>
.nav-dropup {position:relative;margin-left:10px;height:38px;display:inline-block!important;width:115px;}
.nav-dropup .dropdown-menu{position:absolute;top:40px;left:0;z-index:99999;min-width:10rem;padding:.5rem 0;margin:.125rem 0 0;font-size:.875rem;color:#212529;text-align:left;list-style:none;background-color:#fff;background-clip:padding-box;border:1px solid rgba(0,0,0,.15);border-radius:.25rem;display:none;}
.nav-dropup .dropdown-menu a{display:block;width:85%;padding:.25rem 0rem .25rem 1.5rem;clear:both;font-weight:400;color:#212529;text-align:inherit;white-space:nowrap;background-color:transparent;border:0;}
.nav-dropup .dropdown-menu a:hover{color:#16181b;text-decoration:none;background-color:#f5f5f5;}
.layui-btn-gray{background-color:gray;}
</style>
<div class="layui-fluid" id="LAY-component-layer-list">
    <div class="layui-card">
    <div class="layui-card-body table-tool-mini">
        <div class="layui-form toolbar">
            <div class="layui-form-item">
                <input type="hidden" name="channel" id="channel" value="{$channel}">                   
                <div class="layui-input-inline">
                    <select name="typeid" id="typeid">
                    <option value="0">请选择栏目</option>
                    {$arctype_html|raw}
                    </select>
                </div>
                <div class="layui-inline">
                <input type="text" name="keywords" id="keywords" value="" placeholder="标题搜索" class="layui-input">
                </div>
                <div class="layui-inline">
                    <button class="layui-btn icon-btn" lay-filter="formSubSearchUser" lay-submit>
                    <i class="layui-icon">&#xe615;</i>搜索</button>
                    <button class="layui-btn icon-btn" id="gbtypeid" data-type="Article_add" data-typeid="{$typeid}" data-url="{:url('/product/add')}">
                    <i class="layui-icon">&#xe654;</i>新增文档</button>
                    <div class="nav-dropup">
                    <button class="layui-btn layui-btn-danger icon-btn dropdown-bt">批量操作 <i class="layui-icon">&#xe61a;</i></button>
                    <div class="dropdown-menu">
                    <a href="javascript:;" data-url="{:url('/content/batch_copy',['current_channel'=> $channel])}" data-type="batch_copy" id="batch">
                    批量复制</a>
                    <a href="javascript:;" data-url="{:url('/content/batch_move',['current_channel'=> $channel])}" data-type="batch_move_all" id="batch">
                    批量移动</a>
                    <a href="javascript:;" data-url="{:url('/content/batch_del')}" data-type="batch_del" id="batch">
                    批量删除</a>
                    <hr class="layui-bg-gray">
                    <a href="javascript:;" data-url="{:url('/content/add_attr')}" data-type="add_attribute" id="batch">
                    添加属性</a>
                    <a href="javascript:;" data-url="{:url('/content/del_attr')}" data-type="del_attribute" id="batch">
                    删除属性</a>  
                    </div>
                    </div>
                </div>
            </div>
        </div>
        <table class="layui-table" id="articlelist" lay-filter="articlelist"></table>
    </div>
    </div>
</div>
<script type="text/html" id="tableState">
<input type="checkbox" name="status" data-id="{{d.aid}}" value="{{d.status}}" lay-filter="status" lay-skin="switch" lay-text="正常|锁定" {{d.status == 1 ? 'checked':''}}>
</script>
<script type="text/html" id="userTbBar">
<a class="layui-btn layui-btn-primary layui-btn-sm" data-type="Article_edit"  data-id="{{d.aid}}">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-sm" data-type="Article_del" data-url="{:url('/content/batch_del')}" data-id="{{d.aid}}">删除</a>
<a class="layui-btn layui-btn-warm layui-btn-sm" href="{{d.arcurl}}" target="_blank">浏览</a>
</script>
{include file="public/footer"/}
<script>
    layui.use(['layer', 'form', 'table'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;

        // 渲染表格
        var insTb = table.render({
            elem: '#articlelist',
            url: "{:url('/product/index',['channel'=>$channel,'sontypeid'=>$typeid])}",
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'checkbox'},
                {field:'aid',title:'ID',width:60},
                {field: 'title', title: '标题',templet: function (d) {
                    if (d.is_b) {
                        var html = '<font style="font-weight:bold;">'+d.title+'</font>';
                    } else{
                        var html = '<font>'+d.title+'</font>';
                    }
                    if (d.is_head) {
                       html += "<span style='color:red;margin-left:5px;'>[<b style='font-size:12px;'>头条</b>]</span>";
                    } 
                    if (d.is_recom) {
                       html += "<span style='color:red;margin-left:5px;'>[<b style='font-size:12px;'>推荐</b>]</span>";
                    } 
                    if (d.is_special) {
                       html += "<span style='color:red;margin-left:5px;'>[<b style='font-size:12px;'>特推</b>]</span>";
                    } 
                    if (d.is_litpic) {
                       html += " <a href='javascript:void(0);' onclick=BigImages('"+d.litpic+"')><image style='max-width:30px;max-height:30px;' src="+d.litpic+"/></a>";
                    } 
                    if (d.is_jump) {
                       html += "<span style='color:red;margin-left:5px;'>[<b style='font-size:12px;'>跳转</b>]</span>";
                    } 
                    return html;
                }},
                {field: 'typename',title: '所属栏目',align: 'center',templet: function (d) {
                    if(d.typename){
                       var html = "<font>"+d.typename+"</font>";
                    }else{
                       var html = "<font style='color:red;'>数据出错！</font>"; 
                    }
                    return html;
                }, width: 150},
                {field: 'status', templet: '#tableState', title: '状态',align: 'center',width: 100},
                {field: 'click', title: '浏览量',align: 'center',width: 80},
                {field: 'update_time', title: '更新时间',align: 'center', width:200},
                {title: '排序',align: 'center',templet: function (d) {
                    if(d.sort_order){
                       var html = "<input type='text' size='4' data-id='"+d.aid+"' value='"+d.sort_order+"' id='sort_order' class='layui-input' style='height:28px;'/>";
                    }else{
                       var html = ""+d.sort_order+""; 
                    }
                    return html;
                }, width: 80},
                {title: '操作',templet: '#userTbBar',align: 'center', width: 200},
            ]]
        });


        form.on('submit(formSubSearchUser)', function (data) {
            $("#gbtypeid").attr("data-typeid",data.field.typeid);
            insTb.reload({where:data.field,page:{curr: 1}},'data');
        });


        $(document).on("click","#LAY-component-layer-list .layui-btn",function(){
          var type = $(this).data('type');
          active[type] && active[type].call(this);
        });

        $(document).on("click","#LAY-component-layer-list #batch",function(){
          var type = $(this).data('type');
          active[type] && active[type].call(this);
        });

        // 触发事件
        var active = {
            Article_add: function(){
                var obj = this;
                var typeid = $(obj).attr('data-typeid');
                layer.open({
                    type: 2,
                    title: false,
                    closeBtn: false,
                    fixed: true,
                    shadeClose: false,
                    shade: 0.3,
                    area: ['100%', '100%'],
                    content: $(this).attr('data-url')+"?typeid="+typeid
                });
            },
            Article_edit: function(){
                var obj = this;
                var id = $(obj).attr('data-id');
                layer.open({
                    type: 2,
                    title: false,
                    closeBtn: false,
                    fixed: true,
                    shadeClose: false,
                    shade: 0.3,
                    area: ['100%', '100%'],
                    content: '{:url("/product/edit")}?id='+id
                });
            },
            Article_del: function(){
                delfun(this);
            },
            batch_del: function(){
                var checkRows = table.checkStatus('articlelist');
                if (checkRows.data.length === 0) {
                    layer.msg('请选择要删除的数据', {icon: 2,time:1000});
                    return;
                }
                var ids = checkRows.data.map(function (d) {
                    return d.aid;
                });
                batch_del(this, ids);
            },
            add_attribute: function(){
                var checkRows = table.checkStatus('articlelist');
                if (checkRows.data.length === 0) {
                    layer.msg('请至少选择一项', {icon: 2,time:1000});
                    return;
                }
                var ids = checkRows.data.map(function (d) {
                    return d.aid;
                });
                func_haddle_attribute(this, ids,'添加');
            },
            del_attribute: function(){
                var checkRows = table.checkStatus('articlelist');
                if (checkRows.data.length === 0) {
                    layer.msg('请至少选择一项', {icon: 2,time:1000});
                    return;
                }
                var ids = checkRows.data.map(function (d) {
                    return d.aid;
                });
                func_haddle_attribute(this, ids,'删除');
            },
            batch_copy: function(){
                $(".dropdown-menu").slideUp(200);
                event.stopPropagation();
                var checkRows = table.checkStatus('articlelist');
                if (checkRows.data.length === 0) {
                    layer.msg('请至少选择一项', {icon: 2,time:1000});
                    return;
                }
                var ids = checkRows.data.map(function (d) {
                    return d.aid;
                });
                func_batch_copy(this, ids);
            },
            batch_move_all: function(){
                $(".dropdown-menu").slideUp(200);
                event.stopPropagation();
                var checkRows = table.checkStatus('articlelist');
                if (checkRows.data.length === 0) {
                    layer.msg('请至少选择一项', {icon: 2,time:1000});
                    return;
                }
                var ids = checkRows.data.map(function (d) {
                    return d.aid;
                });
                func_move(this, ids);
            }
        };

        //开启关闭
        form.on('switch(status)', function(obj){
            var dataid = $(this).attr('data-id');
            var pcfurl = '{:url("/ajax/ajax_changeTableVal")}';
            if (obj.elem.checked){
                $(this).val(1);
            }else{
                $(this).val(0);
            }
            changeTableVal('archives','aid',dataid,'status',this,pcfurl,'content/index');
        });

        // 监听排序
        $(document).on("change","#LAY-component-layer-list #sort_order",function(){
            var dataid = $(this).attr('data-id');
            var pcfurl = '{:url("/ajax/ajax_changeTableVal")}';
            changeTableVal('archives','aid',dataid,'sort_order',this,pcfurl,'content/index');
        })

    });

    $(".dropdown-bt").click(function(){
        $(".dropdown-menu").slideToggle(200);
        event.stopPropagation();
    });

    $(document).click(function(){
        $(".dropdown-menu").slideUp(200);
        event.stopPropagation();
    });

    //批量属性
    function func_haddle_attribute(obj, name, text)
    {
        aids = name;
        var url = $(obj).attr('data-url');
        layer.open({
            type: 2,
            title: '批量'+text+'属性',
            fixed: true,
            shadeClose: false,
            shade: 0.3,
            maxmin: false,
            area: ['450px', '270px'],
            content: url
        });
    };

    // 批量移动
    function func_move(obj, name)
    {
        aids = name;
        var url = $(obj).attr('data-url');
        layer.open({
            type: 2,
            title: '移动文档',
            fixed: true,
            shadeClose: false,
            shade: 0.3,
            maxmin: false,
            area: ['450px', '350px'],
            content: url
        });
    };

    //批量复制
    function func_batch_copy(obj, name)
    {
        aids = name;
        var url = $(obj).attr('data-url');
        layer.open({
            type: 2,
            title: '批量复制',
            fixed: true,
            shadeClose: false,
            shade: 0.3,
            maxmin: false,
            area: ['450px', '330px'],
            content: url
        });
    };
    
    var aids;
    //获取修改之前的内容
    function get_aids(){
        return aids;
    }

</script>
</body>
</html>